<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
  <h1>我是Vue组件</h1>
  <wind1></wind1>
</div>
<template id="cpn1">
  <div>
    <h2>我是子组件1</h2>
    <wind2></wind2>
  </div>
</template>
<template id="cpn2">
  <div>
    <h3>我是子组件2</h3>
    <button @click="cpn2Click">按钮</button>
  </div>
</template>
<script>
  // 1、Vue组件
  var vm = new Vue({
    el: '#app',
    data: {
      msg: "我是Vue的msg~！"
    },
    // 2、组件2
    components: {
      wind1: {
        template: "#cpn1",
        data() {
          return {
            msg: "我是wind1的msg~！"
          }
        },
        // 3、组件3
        components: {
          wind2: {
            template: "#cpn2",
            data() {
              return {
                msg: "我是wind2的msg~！"
              }
            },
            methods: {
              cpn2Click() {
                // $parent
                console.log(this.$parent);
                // $root
                console.log(this.$root);
              }
            }
          }
        }
      }
    }
  })
</script>
</body>
</html>